﻿<template>
    <div class="l-rblock l-form-viewer" style="padding:8px;">
        <el-form
            :model="formData"
            :rules="rules"
            size="mini"
            labelPosition="right"
            labelWidth="80px"
            ref="form"
            >
            <div class="l-auto-window only-tabs">
                <el-tabs v-model="activeName" type="card">
                    <el-tab-pane class="l-tabs-container" :label="$t('主表信息')" name="tab0">
                        <el-row :gutter="0">
                            <div class="l-rblock">
                                <el-col v-show="false" :span="24" >
                                    <el-form-item 
                                        :label="$t('唯一标识(GUID)')" 
                                        prop="case_erp_devicewarn_f_Id"
                                        > 
                                        <l-guid size="mini" v-model="formData.case_erp_devicewarn_f_Id" />
                                    </el-form-item>
                                </el-col>
                                <el-col v-if="lr_formLookAuth('case_erp_devicewarn_f_UserId')" :span="24" >
                                    <el-form-item 
                                        :label="$t('处理人')" 
                                        prop="case_erp_devicewarn_f_UserId"
                                        > 
                                        <l-user-select :disabled="!lr_formEditAuth('case_erp_devicewarn_f_UserId',isReadOnly)"  v-model="formData.case_erp_devicewarn_f_UserId" />
                                    </el-form-item>
                                </el-col>
                                <el-col v-if="lr_formLookAuth('case_erp_devicewarn_f_Level')" :span="24" >
                                    <el-form-item 
                                        :label="$t('故障等级')" 
                                        prop="case_erp_devicewarn_f_Level"
                                        > 
                                        <l-select :disabled="!lr_formEditAuth('case_erp_devicewarn_f_Level',false || isReadOnly)"  :options="case_erp_devicewarn_f_LevelOptions" v-model="formData.case_erp_devicewarn_f_Level" />
                                    </el-form-item>
                                </el-col>
                                <el-col v-if="lr_formLookAuth('case_erp_devicewarn_f_Description')" :span="24" >
                                    <el-form-item 
                                        :label="$t('故障描述')" 
                                        prop="case_erp_devicewarn_f_Description"
                                        > 
                                        <el-input type="textarea"  :disabled="!lr_formEditAuth('case_erp_devicewarn_f_Description',isReadOnly)" :rows="4" v-model="formData.case_erp_devicewarn_f_Description" :placeholder="$t('please enter')" />
                                    </el-form-item>
                                </el-col>

                                 <el-col v-if="lr_formLookAuth('case_erp_devicewarn_f_DealWay')" :span="24" >
                                    <el-form-item 
                                        :label="$t('处理办法')" 
                                        prop="case_erp_devicewarn_f_DealWay"
                                        > 
                                        <el-input type="textarea"  :disabled="!lr_formEditAuth('case_erp_devicewarn_f_DealWay',isReadOnly)" :rows="4" v-model="formData.case_erp_devicewarn_f_DealWay" :placeholder="$t('please enter')" />
                                    </el-form-item>
                                </el-col>



                                <el-col v-if="lr_formLookAuth('1670331401078_94069')"  :span="24" >
                                    <el-divider content-position="center"></el-divider>
                                </el-col>
                                <el-col v-if="lr_formLookAuth('case_erp_devicewarn_f_File')" :span="24" >
                                    <el-form-item 
                                        :label="$t('附件')" 
                                        prop="case_erp_devicewarn_f_File"
                                        > 
                                        <l-upload  
                                            listType="picture-card"
                                            :disabled="!lr_formEditAuth('case_erp_devicewarn_f_File',false || isReadOnly)" 
                                            v-model="formData.case_erp_devicewarn_f_File" 
                                            :placeholder="$t('please enter')" />
                                    </el-form-item>
                                </el-col>

                                <el-col v-if="lr_formLookAuth('case_erp_devicewarn_f_State')" :span="24" >
                                    <el-form-item 
                                        :label="$t('选择状态')" 
                                        prop="case_erp_devicewarn_f_State"
                                        > 
                                        <l-radio :disabled="!lr_formEditAuth('case_erp_devicewarn_f_State',false || isReadOnly)"  :options="case_erp_devicewarn_f_StateOptions" v-model="formData.case_erp_devicewarn_f_State" />
                                    </el-form-item>
                                </el-col>
                            </div>
                        </el-row>
                    </el-tab-pane>

                </el-tabs>
            </div>
        </el-form>
    </div>
</template>
<script>
const api = window.$api.erpcase.devicewarn

export default {
    props: {
        isReadOnly: {
            type: Boolean,
            default: false
        }
    },
    data(){
        return {
            moduleCode: 'ERP_DeviceWarn',
            activeName: 'tab0',
            formData: {
                case_erp_devicewarn_f_Id:"",            // 唯一标识(GUID)
                case_erp_devicewarn_f_UserId:"",        // 处理人
                case_erp_devicewarn_f_Level:"",         // 故障等级
                case_erp_devicewarn_f_Description:"",   // 故障描述
                case_erp_devicewarn_f_DealWay:"",       // 处理方法
                case_erp_devicewarn_f_File:"",          // 附件
                case_erp_devicewarn_f_State:"0",        // 选择状态

            },
            rules: {
                case_erp_devicewarn_f_UserId:[
                    { required: true, message: 'please select处理人' },
                ],
                case_erp_devicewarn_f_State:[
                    { required: true, message: 'please select选择状态' },
                ],
                 case_erp_devicewarn_f_DealWay:[
                    { required: true, message: '请填写处理办法' },
                ],

            },
            
        };
    },
    computed: {
        case_erp_devicewarn_f_LevelOptions(){
            return [{"value":"0","label":"一级告警"},{"value":"1","label":"二级告警"},{"value":"2","label":"三级告警"}]
        },
        case_erp_devicewarn_f_StateOptions(){
            return [{"value":0,"label":"已处理"},{"value":1,"label":"待处理"}]
        },

    },

    mounted(){},
    methods: {
        
        // Reset表单
        resetForm() {
            this.$formClear(this.$refs.form)
            this.activeName = 'tab0'
        },
        // 校验表单
        async validateForm() {
            if (!await this.$formValidateWraper(this.$refs.form)) {
                return false  
            }
            return true
        },
        // 设置表单数据
        setForm(data) {
            this.$setFormData(this.formData,data,'case_erp_devicewarn')
        },
        // 获取表单数据
        getForm() {
            return this.$getFormData(this.formData,'case_erp_devicewarn')
        },

        async loadFormData({ keyValue/*,params,node*/ }) {//  keyValue 流程中相当于流程processId,params 传递参数,node 流程节点
            const data = await this.$awaitWraper(api.get(keyValue))
            if (data) {
                this.setForm(data)
                return true
            }
            else {
                return false
            }
        },
         async saveForm({ keyValue, isEdit/*,code,node*/ }) {// isEdit 是否更新数据, keyValue 流程中相当于流程processId,code 表示流程中的操作码,node 流程节点
            const postData = this.getForm()
            if (isEdit) {// Edit
                return await this.$awaitWraper(api.update(keyValue, postData))
            }
            else {// Add
                postData.f_Id = keyValue

                return await this.$awaitWraper(api.add(postData))
            }
        },

    
    }
}
</script>